﻿using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using SharpAnalyzer.Utilities;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace SharpAnalyzer.Collectors
{
    // SyntaxWalkers
    // https://github.com/dotnet/roslyn/wiki/Getting-Started-C%23-Syntax-Analysis
    internal sealed class NamespaceCollectorSyntaxWalker : CSharpSyntaxWalker
    {
        private readonly List<NamespaceDeclarationSyntax> namespaces = new List<NamespaceDeclarationSyntax>();

        public NamespaceCollectorSyntaxWalker()
          : base(SyntaxWalkerDepth.Node)
        {
        }

        public IEnumerable<NamespaceDeclarationSyntax> GetNamespaces(SyntaxNode commonNode)
        {
            Verify.NotNull(() => commonNode);

            if (commonNode != null)
                Visit(commonNode);
            return namespaces.AsReadOnly();
        }

        public override void VisitNamespaceDeclaration(NamespaceDeclarationSyntax node)
        {
            base.VisitNamespaceDeclaration(node);
            namespaces.Add(node);
        }
    }
}


